﻿#region
using System;
using System.IO;
using System.Windows.Forms;
using EndlessDownloader.Properties;

#endregion

namespace EndlessDownloader
{
    public partial class StartForm : BaseForm
    {
        public StartForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
                return;

            nudPage.Value = Settings.Default.StartPage;
            nudDigit.Value = Settings.Default.FileNameDigit;
            nudInterval.Value = Settings.Default.DownloadInterval;
            chkLatestImageVisible.Checked = Settings.Default.LatestImageVisible;
            chkNoPorn.Checked = Settings.Default.LatestImageVisible;

            if (Directory.Exists(Settings.Default.SaveFolder))
                txtSaveFodler.Text = Settings.Default.SaveFolder;
            else
                txtSaveFodler.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(txtSaveFodler.Text) == false)
            {
                MessageBox.Show("잘못된 저장위치입니다.");
                return;
            }

            Settings.Default.StartPage = Convert.ToInt32(nudPage.Value);
            Settings.Default.FileNameDigit = Convert.ToInt32(nudDigit.Value);
            Settings.Default.DownloadInterval = Convert.ToInt32(nudInterval.Value);
            Settings.Default.LatestImageVisible = chkLatestImageVisible.Checked;
            Settings.Default.NoPorn = chkNoPorn.Checked;
            Settings.Default.SaveFolder = txtSaveFodler.Text;

            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (fbdFolder.ShowDialog() == DialogResult.OK)
                txtSaveFodler.Text = fbdFolder.SelectedPath;
        }

        private void nudPage_ValueChanged(object sender, EventArgs e)
        {
            chkNoPorn.Enabled = nudPage.Value == 505;
        }
    }
}